package com.atom.module.coroutine.test

import com.atom.module.coroutine.core.launch
import com.atom.module.coroutine.scope.ContextScope
import com.atom.module.coroutine.scope.GlobalScope
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.suspendCoroutine

fun main() {
//    调用挂起函数通过反射()
    val launch = GlobalScope.launch {
        launchHello()
    }
    Thread.sleep(2000)
}

//-------------------------------------------------------------------------
fun `调用挂起函数通过反射`() {
    val h = ::hello2
    h.call(object : Continuation<Int> {
        override val context: CoroutineContext
            get() = EmptyCoroutineContext

        override fun resumeWith(result: Result<Int>) {
            print("result : ${result.isSuccess} value:${result.getOrNull()}")
        }
    })
}

suspend fun hello2(): Int = suspendCoroutine {
    print("hello")
    it.resumeWith(Result.success(0))
}

suspend fun launchHello(){
    print("hello")
}